using IrisGenerator.Common.DataTypes;
using DAL = IrisGenerator.Common.DatabaseModel.DataAccess;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.DatabaseModel {
    
    
    public partial class RequestParameter {
        
        private System.Nullable<System.Guid> _reqParId;
        
        private System.Nullable<System.Guid> _metId;
        
        private System.Nullable<System.Guid> _reqId;
        
        private System.Nullable<System.Guid> _colId;
        
        private string _reqParName;
        
        private string _reqParLength;
        
        private System.Nullable<int> _reqParPrecision;
        
        private System.Nullable<int> _reqParDirection;
        
        private string _reqParFormatedName;
        
        private Column _column;
        
        private Metatype _metatype;
        
        private Request _request;
        
        public virtual System.Nullable<System.Guid> ReqParId {
            get {
                return _reqParId;
            }
            set {
                _reqParId = value;
            }
        }
        
        public virtual string ReqParName {
            get {
                return _reqParName;
            }
            set {
                _reqParName = value;
            }
        }
        
        public virtual string ReqParLength {
            get {
                return _reqParLength;
            }
            set {
                _reqParLength = value;
            }
        }
        
        public virtual System.Nullable<int> ReqParPrecision {
            get {
                return _reqParPrecision;
            }
            set {
                _reqParPrecision = value;
            }
        }
        
        public virtual System.Nullable<int> ReqParDirection {
            get {
                return _reqParDirection;
            }
            set {
                _reqParDirection = value;
            }
        }
        
        public virtual string ReqParFormatedName {
            get {
                return _reqParFormatedName;
            }
            set {
                _reqParFormatedName = value;
            }
        }
        
        public virtual Column Column {
            get {
                if ((this._column == null)) {
                    this._column = IrisGenerator.Common.DatabaseModel.Column.Load(this._colId);
                }
                return this._column;
            }
            set {
                _column = value;
            }
        }
        
        public virtual Metatype Metatype {
            get {
                if ((this._metatype == null)) {
                    this._metatype = Metatype.Load(this._metId);
                }
                return this._metatype;
            }
            set {
                _metatype = value;
            }
        }
        
        public virtual Request Request {
            get {
                if ((this._request == null)) {
                    this._request = IrisGenerator.Common.DatabaseModel.Request.Load(this._reqId);
                }
                return this._request;
            }
            set {
                _request = value;
            }
        }
        
        private void Clean() {
            this.ReqParId = null;
            this._metId = null;
            this._reqId = null;
            this._colId = null;
            this.ReqParName = string.Empty;
            this.ReqParLength = string.Empty;
            this.ReqParPrecision = null;
            this.ReqParDirection = null;
            this.ReqParFormatedName = string.Empty;
            this.Column = null;
            this.Metatype = null;
            this.Request = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["REQ_PAR_ID"] != System.DBNull.Value)) {
                this.ReqParId = ((System.Nullable<System.Guid>)(dr["REQ_PAR_ID"]));
            }
            if ((dr["MET_ID"] != System.DBNull.Value)) {
                this._metId = ((System.Nullable<System.Guid>)(dr["MET_ID"]));
            }
            if ((dr["REQ_ID"] != System.DBNull.Value)) {
                this._reqId = ((System.Nullable<System.Guid>)(dr["REQ_ID"]));
            }
            if ((dr["COL_ID"] != System.DBNull.Value)) {
                this._colId = ((System.Nullable<System.Guid>)(dr["COL_ID"]));
            }
            if ((dr["REQ_PAR_NAME"] != System.DBNull.Value)) {
                this.ReqParName = ((string)(dr["REQ_PAR_NAME"]));
            }
            if ((dr["REQ_PAR_LENGTH"] != System.DBNull.Value)) {
                this.ReqParLength = ((string)(dr["REQ_PAR_LENGTH"]));
            }
            if ((dr["REQ_PAR_PRECISION"] != System.DBNull.Value)) {
                this.ReqParPrecision = ((System.Nullable<int>)(dr["REQ_PAR_PRECISION"]));
            }
            if ((dr["REQ_PAR_DIRECTION"] != System.DBNull.Value)) {
                this.ReqParDirection = ((System.Nullable<int>)(dr["REQ_PAR_DIRECTION"]));
            }
            if ((dr["REQ_PAR_FORMATED_NAME"] != System.DBNull.Value)) {
                this.ReqParFormatedName = ((string)(dr["REQ_PAR_FORMATED_NAME"]));
            }
        }
        
        public static RequestParameterCollection Select_REQUEST_PARAMETER_By_COL_ID(System.Nullable<System.Guid> COL_ID) {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.Select_REQUEST_PARAMETER_By_COL_ID(COL_ID);
                RequestParameterCollection collection = new RequestParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        RequestParameter obj = new RequestParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestParameterCollection Select_REQUEST_PARAMETER_By_MET_ID(System.Nullable<System.Guid> MET_ID) {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.Select_REQUEST_PARAMETER_By_MET_ID(MET_ID);
                RequestParameterCollection collection = new RequestParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        RequestParameter obj = new RequestParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestParameterCollection Select_REQUEST_PARAMETER_By_REQ_ID(System.Nullable<System.Guid> REQ_ID) {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.Select_REQUEST_PARAMETER_By_REQ_ID(REQ_ID);
                RequestParameterCollection collection = new RequestParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        RequestParameter obj = new RequestParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestParameterCollection GetAll() {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.REQUEST_PARAMETER_Select_All();
                RequestParameterCollection collection = new RequestParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        RequestParameter obj = new RequestParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static RequestParameter Load(System.Nullable<System.Guid> REQ_PAR_ID) {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.REQUEST_PARAMETER_Select_One(REQ_PAR_ID);
                RequestParameter obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new RequestParameter();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                System.Data.DataSet ds = dbo.REQUEST_PARAMETER_Select_One(this.ReqParId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                dbo.REQUEST_PARAMETER_Insert(this.Metatype.MetId, 
                    this.Request.ReqId, this.Column.ColId, this.ReqParName, this.ReqParLength, this.ReqParPrecision, this.ReqParDirection, this.ReqParFormatedName);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                dbo.REQUEST_PARAMETER_Delete(this.ReqParId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            DAL.RequestParameter dbo = null;
            try {
                dbo = new DAL.RequestParameter();
                dbo.REQUEST_PARAMETER_Update(this.ReqParId, this._metId, this._reqId, this._colId, this.ReqParName, this.ReqParLength, this.ReqParPrecision, this.ReqParDirection, this.ReqParFormatedName);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
